var skill = {
	getBusShopIDList: function() {
		return this.shops || (this.shops = []);
	},
	getShopList: function() {
		var shop_id_list = this.getBusShopIDList();
		var shop_list = $Array.clearNull(shop_id_list.map(shop_id => BusShopCon.get(shop_id)));
		if (shop_list.length !== shop_id_list.length) {
			this.shops = shop_list.map(shop => shop._id);
			this.save();
		}
		return shop_list;
	},
	getShopListByState: function(state) {
		return this.getShopList().filter(shop => shop.state === state);
	},
	//不安全，不检查直接增加门店ID
	_addShop: function(bus_shop_id) {
		var shops = this.getBusShopIDList();
		if (shops.indexOf(bus_shop_id) === -1) {
			shops.push(bus_shop_id);
			this.save();
		}
	},
	_removeShop: function(bus_shop_id) {
		var shops = this.getBusShopIDList();
		$Array.remove(shops, bus_shop_id);
		this.save();
	},
	applyAddShop: function(bus_shop_info) {
		bus_shop_info.state = BusShopCon.STATE.未审核;
		bus_shop_info.MA_id = this._id;
		bus_shop_info.bus_id = this.bus_id;
		return new BusShopCon(bus_shop_info);
	}
};

module.exports = skill;

var db = require("../db/index");
var DomainCon = require("../domain/_con");
var GoodsCon = require("../goods/_con");
var UserCon = require("../user/_con");
var BusCon = require("../bus/_con");
var BusMACon = require("../bus.MA/_con");
var BusShopCon = require("../bus.shop/_con");
var AchCon = require("../ach/_con");
var ClassifyCon = require("../bus.classify/_con");
var TagCon = require("../bus.tag/_con");
var LeagueCon = require("../league/_con");
var BuffCon = require("../buff/_con");
var BusUserBindCon = require("../bus_user_bind/_con");
var BusGuideCon = require("../bus.guide/_con");
var CommentCon = require("../comment/_con");
var config = require("../_include/config");
var data_cut = require("../_include/data_cut");
var helper = require("../_include/helper");
var md5 = require("../_include/md5");
var $Object = require("../_include/$.Object");
var $Array = require("../_include/$.Array");
var tld = require('tldjs');
var fs = require("fs");
var Fiber = require('fibers');